import request from '@/utils/request'

/**
 * 短剧场 推荐短剧的接口，
 */
export const apiGetShartVideoList = params => request.get('/video/lists', { params })

/**
 * 视频组合列表 包含了 本周热门， 排行榜，最新
 * 
 */
export const apiGetShartVideoOtherLists = params => request.get('/video/otherlists', { params })


export const apiGetZuiJuLists = params => request.get('/video/recordlists', { params })




/**
 * 获取子分类 
 * @example 返回数据示例
 */
export const apiGetShartVideoSonCategoryList = params => request.get('/videoCategory/sonCategoryLists', { params })

// 
// shopapi/ad/lists?position=2

// 视频广告， banner 图
const AD_LIST_RES = {}
export const apiGetAdList = (params = {}, bool = false) => {
    let newParams = {}
    let isReadCache = bool
    if (params && typeof params === 'object') {
        newParams = Object.assign({}, params)
    }
    if (params && typeof params === 'boolean') {
       isReadCache = params
    }
    return new Promise((resolve, reject) => {
        if (isReadCache && Object.keys(AD_LIST_RES).length) {
            return resolve(AD_LIST_RES)
        }
        // position 位置：1首页 2短剧页
        request.get('/ad/lists', { params: { position: 2, ...newParams} }).then((res) => {
            if (res && !Array.isArray(res) && typeof res === 'object') {
                Object.assign(AD_LIST_RES, res, {
                    list: res.lists || []
                })
                return resolve(AD_LIST_RES)
            }
            return resolve({
                lists: []
            })
            
        }).catch((err) => {
            reject(err)
        })
    })
}